﻿using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.DependencyInjection;

namespace XDQ.VAT
{
    public class ExceptionAppService : IExceptionAppService, ITransientDependency
    {
        public ILogger<ExceptionAppService> Logger { get; set; }
        public Task<DateTime> ErrorAndHandle1()
        {
            try
            {
                return Task.Run<DateTime>(() =>
                {
                    Error();
                    return DateTime.Now;
                });
            }
            catch (Exception exp)
            {
                throw new UserFriendlyException("ErrorAndHandleAsync", null, null, exp);
            }
            finally
            {

            }
            return Task.FromResult(DateTime.Now);
        }

        public Task<DateTime> ErrorAndLog1()
        {
            try
            {
                return Task.Run<DateTime>(() =>
                {
                    Error();
                    return DateTime.Now;
                });
            }
            catch (Exception exp)
            {
                Logger.LogError(exp, "ErrorAndLogAsync");
            }
            finally
            {

            }
            return Task.FromResult(DateTime.Now);
        }
        public Task<DateTime> Error1()
        {
            return Task.Run<DateTime>(() =>
            {
                Error();
                return DateTime.Now;
            });
        }


        public DateTime Error()
        {
            throw new Exception(DateTime.Now.ToString());
        }

        public DateTime ErrorAndLog()
        {
            try
            {
                throw new Exception(DateTime.Now.ToString());
            }
            catch (Exception exp)
            {
                Logger.LogError(exp, "ErrorAndLog");
            }
            return DateTime.Now;
        }

        public DateTime ErrorAndHandle()
        {
            try
            {
                throw new Exception(DateTime.Now.ToString());
            }
            catch (Exception exp)
            {
                throw new UserFriendlyException("ErrorAndHandle", null, null, exp);
            }
        }
    }
}
